﻿(function()
{
	//#region 初始化模块
	var __m = m();
	_helper.addInit(__m, init);
	$('head').append('<link rel="stylesheet" href="' + __m + 'S01/' + $('html').attr('lang') + '/css/common.css">');
    //#endregion

	//#region 初始化页面
	function init(instance, page, panel, url, reload)
	{
		if (reload)
			return;

	    if (page == 'position_add')
	    {
	        //创建对象
	        var position = new Position(instance, panel);

	        //绑定事件
	        $('form:first', panel).submit(position.add);
	    	panel.on('click', '[data-operation=SelectSketchMap]', position.onSelectSketchMapClick)
				 .on('click', '[data-operation=SelectImage]', position.onSelectImageClick);
        }
	    else if (page == 'position_edit')
	    {
	    	//创建对象
	    	var position = new Position(instance, panel);

	    	//绑定事件
	    	$('form:first', panel).submit(position.modify);
	    	panel.on('click', '[data-operation=SelectSketchMap]', position.onSelectSketchMapClick)
				 .on('click', '[data-operation=SelectImage]', position.onSelectImageClick);
	    }
	    else if (page == 'position_list')
		{
	    	//创建对象
	    	var position = new Position(instance, panel);

	    	//绑定事件
	    	panel.on('click', '[data-operation=Recycle],[data-operation=Delete],[data-operation=Recover]', position.update);
		}
	    else if (page == 'type_add')
	    {
	    	//创建对象
	    	var type = new Type(instance, panel);

	    	//绑定事件
	    	$('form:first', panel).submit(type.add);
	    }
	    else if (page == 'type_edit')
	    {
	    	//创建对象
	    	var type = new Type(instance, panel);

	    	//绑定事件
	    	$('form:first', panel).submit(type.modify);
	    }
	    else if (page == 'type_list')
		{
	    	//创建对象
	    	var type = new Type(instance, panel);

	    	//绑定事件
	    	panel.on('click', '[data-operation=Delete]', type.del);
	    }
	    else if (page == 'sub_instance_add')
	    {
	    	//创建对象
	    	var subInstance = new SubInstance(instance, panel);

	    	//绑定事件
	    	$('form:first', panel).submit(subInstance.add);
	    	$('[data-operation=SelectUser]', panel).click(subInstance.onSelectUserClick);
	    	panel.on('click', '[data-page=user_select] td a', subInstance.onUserClick);
	    }
	    else if (page == 'sub_instance_edit')
	    {
	    	//创建对象
	    	var subInstance = new SubInstance(instance, panel);

	    	//绑定事件
	    	$('form:first', panel).submit(subInstance.modify);
	    	$('[data-operation=SelectUser]', panel).click(subInstance.onSelectUserClick);
	    	panel.on('click', '[data-page=user_select] td a', subInstance.onUserClick);
	    }
	    else if (page == 'sub_instance_list')
		{
	    	//创建对象
	    	var subInstance = new SubInstance(instance, panel);

	    	//绑定事件
	    	panel.on('click', '[data-operation=Recycle],[data-operation=Delete],[data-operation=Recover],[data-operation=Check]', subInstance.update);
		}
		else if (page == 'income_list')
		{
		    //创建对象
		    var income = new Income(instance, panel);

		    //绑定事件
		    panel.on('click', '[data-operation=Delete]', income.deleteIncome);
		}
		else if (page == 'income_cpt')
		{
		    //创建对象
		    var income = new Income(instance, panel);

		    //绑定事件
		    panel.on('click', '[data-operation=Settle]', income.settleCpt);

  		}
		else if (page == 'income_cpc')
		{
		    //创建对象
		    var income = new Income(instance, panel);

		    //绑定事件
		    panel.on('click', '[data-operation=Settle]', income.settleCpc);
		}
		else if (page == 'config_basic')
		{
			//创建对象
			var instanceConfig = new InstanceConfig(instance, panel);

			//绑定事件
			panel.on('click', '[name=Rebuild]', instanceConfig.rebuild);
			panel.on('click', '[name=GenerateCacheFile]', instanceConfig.generateCacheFile);
		}
		else if (page == 'type_resource_add')
		{
			//创建对象
			var resource = new TypeResource(instance, panel);

			//绑定事件
			$('form:first', panel).submit(resource.add);
			panel.on('click', '[data-operation=AddFolder]', resource.onAddFolderClick);

		}
		else if (page == 'type_resource_list')
		{	
			//创建对象
			var resource = new TypeResource(instance, panel);

			//绑定事件
			panel.on('click', '[data-operation=DeleteFile]', resource.deleteFile);
			panel.on('click', '[data-operation=DeleteFolder]', resource.onDeleteFolderClick);
		}
		else if (page == 'ad_list')
		{
			//创建对象
			var ad = new Ad(instance, panel);

			//绑定事件
			panel.on('click', '[data-operation=Recycle],[data-operation=Delete],[data-operation=Recover],[data-operation=Check]', ad.update);
			ali.grid($('[data-ali-widget=grid]', panel), 'option', 'onMove', ad.move);
		}
		else if (page == 'ad_add')
		{
			//创建对象
			var ad = new Ad(instance, panel);

			//绑定事件
			$('form:first', panel).submit(ad.add);
			panel.on('click', '[data-operation=SelectImage]', ad.onSelectImageClick);
		}
		else if (page == 'ad_edit')
		{
			//创建对象
			var ad = new Ad(instance, panel);

			//绑定事件
			$('form:first', panel).submit(ad.modify);
			panel.on('click', '[data-operation=SelectImage]', ad.onSelectImageClick);
		}
		else if (page == 'ad_search')
		{
			//创建对象
			var ad = new Ad(instance, panel);

			//绑定事件
			panel.on('click', '[data-operation=Recycle],[data-operation=Delete],[data-operation=Recover],[data-operation=Check]', ad.update);
		}
}
	//#endregion

	//#region 广告位
	function Position(instance, panel)
	{
		var __object = o(arguments.callee);

		this.add = function ()
		{
		    var data = prepareData(this);
		    if (!data)
		        return false;

		    var guid = _helper.post({ instance: instance, object: __object, operation: 'Add', data: data, silent: true });
		    if (guid != null)
		    {
		    	var id = _helper.get({ instance: instance, object: __object, operation: 'GetInnerIDFromGuid', params: 'ID=' + guid });
		    	uploadSketchMap(id);
		    }

		    return false;
		};

		this.modify = function ()
		{
		    var data = prepareData(this);
		    if (!data)
		        return false;

		    _helper.post({ instance: instance, object: __object, operation: 'Modify', data: data, params: 'ID=' + v(panel, 'id'), silent: true });

		    uploadSketchMap(v(panel, 'id'));

		    return false;
		};

		this.update = function ()
		{
			_helper.update({ instance: instance, object: __object, element: this });
		};

		this.onSelectSketchMapClick = function ()
		{
			_helper.openSelectDialog({ element: this, instance: instance, object: __object, operation: 'UploadSketchMap', folder: 'position/sketch_map/' });
		};

		this.onSelectImageClick = function ()
		{
			_helper.openSelectDialog({ element: this, instance: instance, object: __object, operation: 'UploadImage', folder: 'position/image/' });
		};

		function prepareData(form)
		{
		    if (form.Name.value == '')
		    {
		        ali.error(l(__m, 'name_empty'), $.proxy(function () { form.Name.select(); }, this));
		        return null;
		    }

			/*
		    if (form.TypeID.value == '')
		    {
		        ali.error(l(__m, 'select_type'));
		        return null;
			}
			*/

		    if (!form.Width.value.match(/^\d+$/))
		    {
		        ali.error(l(__m, 'width_incorrect'), $.proxy(function () { form.Width.select(); }, this));
		        return null;
		    }

		    if (!form.Height.value.match(/^\d+$/))
		    {
		        ali.error(l(__m, 'height_incorrect'), $.proxy(function () { form.Height.select(); }, this));
		        return null;
		    }

		    if (!form.Price.value.match(/^\d+(\.\d+)?$/))
		    {
		        ali.error(l(__m, 'price_incorrect'), $.proxy(function () { form.Price.select(); }, this));
		        return null;
		    }

		    if (!form.Duration.value.match(/^\d+$/))
		    {
		        ali.error(l(__m, 'duration_incorrect'), $.proxy(function () { form.Duration.select(); }, this));
		        return null;
		    }

		    if (!form.ClickPrice.value.match(/^\d+(\.\d+)?$/))
		    {
		        ali.error(l(__m, 'click_price_incorrect'), $.proxy(function () { form.ClickPrice.select(); }, this));
		        return null;
		    }

		    if (!_helper.isAllowedType(form.SketchMap.value, form.PictureAllowedType.value))
		    {
		        ali.error(l(__m, 'sketch_map_type_must_be') + form.PictureAllowedType.value, $.proxy(function () { form.SketchMap.select(); }, this));
		        return null;
		    }

		    if (!_helper.isAllowedType(form.Image.value, form.PictureAllowedType.value))
		    {
		        ali.error(l(__m, 'image_type_must_be') + form.PictureAllowedType.value, $.proxy(function () { form.Image.select(); }, this));
		        return null;
		    }

		    var data = _helper.serialize(form);

		    return data;
		}

		function uploadSketchMap(id)
		{
		    var upload = $('[name=SketchMap]', panel);
		    if (!ali.uploader(upload.next(), 'needUpload'))
		    {
		        uploadImage(id);
		        return;
		    }

		    ali.uploader(upload.next(), 'upload',
			{
				status: l(__m, 'uploading_sketch_map'),
				lang: _lang,
				instance: instance,
				object: __object,
				operation: 'UploadSketchMap',
				id: id,
				folder: 'position/sketch_map/',
				onComplete: function (result)
		    	{
		    		if (result.error != 0)
		    		{
		    			ali.error(result.message);
		    		}
		    		else
		    		{
		    			upload.parent().find('a:last').attr('href', result.path).find('img').attr('src', result.path);
						_helper.post({ instance: instance, object: __object, operation: 'Modify', data: 'SketchMap=' + encodeURIComponent(result.path), params: 'ID=' + id, silent: true });

		    			uploadImage(id);
		    		}
		    	}
		    });
		}
		
		function uploadImage(id)
		{
		    var upload = $('[name=Image]', panel);
		    if (!ali.uploader(upload.next(), 'needUpload'))
		    {
		    	//生成广告缓存文件
		    	_helper.post({ instance: instance, object: 'InstanceConfig', operation: 'GenerateCacheFile', silent: true });

		    	ali.success(_lang_operation_success);
		        ali.working();
		        return;
		    }

		    ali.uploader(upload.next(), 'upload',
			{
				status: l(__m, 'uploading_image'),
				lang: _lang,
				instance: instance,
				object: __object,
				operation: 'UploadImage',
				id: id,
				folder: 'position/image/',
				addWaterMark: upload.parent().find(':checkbox:last').prop('checked'),
				onComplete: function (result)
		    	{
		    		if (result.error != 0)
		    		{
		    			ali.error(result.message);
		    		}
		            else
		            {
		    			upload.parent().find('a:last').attr('href', result.path).find('img').attr('src', result.path);
						_helper.post({ instance: instance, object: __object, operation: 'Modify', data: 'Image=' + encodeURIComponent(result.path), params: 'ID=' + id, silent: true });

		            	//生成广告缓存文件
		                _helper.post({ instance: instance, object: 'InstanceConfig', operation: 'GenerateCacheFile', silent: true });

		                ali.success(_lang_operation_success);
		                ali.working();
		            }
		        }
		    });
		}
    }
    //#endregion

	//#region 广告管理
	function Ad(instance, panel)
	{
		var __object = o(arguments.callee);

		this.add = function ()
		{
			var data = prepareData(this);
			if (!data)
				return false;

			var guid = _helper.post({ instance: instance, object: __object, operation: 'Add', data: data, silent: true });
			if (guid != null)
			{
				var id = _helper.get({ instance: instance, object: __object, operation: 'GetInnerIDFromGuid', params: 'ID=' + guid });
				uploadImage(id);
			}

			return false;
		};

		this.modify = function ()
		{
			var data = prepareData(this);
			if (!data)
				return false;

			_helper.post({ instance: instance, object: __object, operation: 'Modify', data: data, params: 'ID=' + v(panel, 'id'), silent: true });

			uploadImage(v(panel, 'id'));

			return false;
		};

		this.update = function ()
		{
			_helper.update({ instance: instance, object: __object, element: this });
		};

		this.move = function (element, from, to)
		{
			_helper.post({ instance: instance, object: __object, operation: 'Move', params: 'From=' + from + '&To=' + to });
		};

		this.onSelectImageClick = function ()
		{
			_helper.openSelectDialog({ element: this, instance: instance, object: __object, operation: 'UploadImage', folder: 'ad/' });
		};

		function prepareData(form)
		{
			if (form.Title.value == "")
			{
				ali.error(l(__m, 'title_empty'), $.proxy(function () { form.Title.select(); }, this));
				return null;
			}

			if (!form.Width.value.match(/^\d+$/))
			{
				ali.error(l(__m, 'width_incorrect'), $.proxy(function () { form.Width.select(); }, this));
				return null;
			}

			if (!form.Height.value.match(/^\d+$/))
			{
				ali.error(l(__m, 'height_incorrect'), $.proxy(function () { form.Height.select(); }, this));
				return null;
			}

			if (!_helper.isAllowedType(form.Image.value, form.PictureAllowedType.value))
			{
				ali.error(l(__m, 'image_type_must_be') + form.PictureAllowedType.value, $.proxy(function () { form.Image.select(); }, this));
				return null;
			}

			var re = /^(\d{1,4})(-|\/)(\d{1,2})(-|\/)(\d{1,2})( (\d{1,2}):(\d{1,2}):(\d{1,2}))?$/;	
			if (form.StartTime.value == "" || !re.test(form.StartTime.value))
			{
				ali.error(l(__m, 'start_time_incorrect'), $.proxy(function () { form.StartTime.select(); }, this));
				return null;
			}
	
			if (form.EndTime.value != "" && !re.test(form.EndTime.value))
			{
				ali.error(l(__m, 'end_time_incorrect'), $.proxy(function () { form.EndTime.select(); }, this));
				return null;
			}

			var data = _helper.serialize(form);

			return data;
		}

		function uploadImage(id)
		{
			var upload = $('[name=Image]', panel);
			if (!ali.uploader(upload.next(), 'needUpload'))
			{
				//生成广告缓存文件
				_helper.post({ instance: instance, object: 'InstanceConfig', operation: 'GenerateCacheFile', silent: true });

				ali.success(_lang_operation_success);
				ali.working();
				return;
			}

			ali.uploader(upload.next(), 'upload',
			{
				status: l(__m, 'uploading_image'),
				lang: _lang,
				instance: instance,
				object: __object,
				operation: 'UploadImage',
				id: id,
				folder: 'ad/',
				addWaterMark: upload.parent().find(':checkbox:last').prop('checked'),
				onComplete: function (result)
				{
					if (result.error != 0)
					{
						ali.error(result.message);
					}
					else
					{
						upload.parent().find('a:last').attr('href', result.path).find('img').attr('src', result.path);
						_helper.post({ instance: instance, object: __object, operation: 'Modify', data: 'Image=' + encodeURIComponent(result.path), params: 'ID=' + id, silent: true });

						//生成广告缓存文件
						_helper.post({ instance: instance, object: 'InstanceConfig', operation: 'GenerateCacheFile', silent: true });

						ali.success(_lang_operation_success);
						ali.working();
					}
				}
			});

		}
	}
	//#endregion

    //#region 类型
	function Type(instance, panel)
	{
		var __object = o(arguments.callee);

		this.add = function ()
		{
			var data = prepareData(this);
			if (!data)
				return false;

			var guid = _helper.post({ instance: instance, object: __object, operation: 'Add', data: data, silent: true });
			if (guid != null)
			{
				var id = _helper.get({ instance: instance, object: __object, operation: 'GetInnerIDFromGuid', params: 'ID=' + guid });
				uploadTemplate(id);
			}
			return false;
		};

		this.del = function ()
		{
			var tr = $(this).closest('tr');
			var id = tr.data('id');
			ali.confirm(_lang_confirm_delete, $.proxy(function (returnValue)
			{
				if (returnValue)
				{
					//服务器中删除
					_helper.post({ instance: instance, object: __object, operation: 'Delete', params: '&ID=' + id });

					//客户端中删除
					ali.grid($('[data-ali-widget=grid]', panel), 'deleteRow', tr[0].rowIndex);
				}

			}, this));

			return false;
		};

		this.modify = function ()
		{
			var data = prepareData(this);
			if (!data)
				return false;

			_helper.post({ instance: instance, object: __object, operation: 'Modify', data: data, params: 'ID=' + v(panel, 'id'), silent: true });

			uploadTemplate(v(panel, 'id'));

			return false;
		};

		function prepareData(form)
		{
			if (form.Name.value == '')
			{
				ali.error(l(__m, 'name_empty'), $.proxy(function () { form.Name.select(); }, this));
				return null;
			}

			if (form.Template.value != '' && !form.Template.value.match(/(\\|\/)template\.swf$/))
			{
				ali.error(l(__m, 'name_must_be_template_swf'), $.proxy(function () { form.Template.select(); }, this));
				return null;
			}

			if (!_helper.isAllowedType(form.Template.value, form.TemplateAllowedType.value))
			{
				ali.error(l(__m, 'type_must_be') + form.TemplateAllowedType.value, $.proxy(function () { form.Template.select(); }, this));
				return null;
			}

			var data = _helper.serialize(form);

			return data;
		}

		function uploadTemplate(id)
		{
			var upload = $('[name=Template]', panel);
			if (!ali.uploader(upload.next(), 'needUpload'))
			{
				ali.success(_lang_operation_success);
				ali.working();
				return;
			}

			ali.uploader(upload.next(), 'upload',
			{
				status: l(__m, 'uploading'),
				nameBySystem: false,
				overrite: true,
				lang: _lang,
				instance: instance,
				object: __object,
				operation: 'UploadTemplate',
				folder: v(panel,'modulePath') + 'common/' + _lang + '/type/' + id + '/',
				onComplete: function (result)
				{
					if (result.error != 0)
					{
						ali.error(result.message);
					}
					else
					{
						ali.success(_lang_operation_success);
						ali.working();
					}
				}
			});
		}
	}
    //#endregion
    
    //#region 类型.资源
	function TypeResource(instance, panel)
	{
		var __object = 'Type.Resource';

		this.add = function ()
		{
			var upload = $('[name=File]', panel);
			if (!ali.uploader(upload.next(), 'needUpload'))
			{
				ali.error(l(__m, 'select_file'));
				return false;
			}

			if (!_helper.isAllowedType(this.File.value, this.AllowedType.value))
			{
				ali.error(l(__m, 'file_type_must_be') + this.AllowedType.value, $.proxy(function () { this.File.select(); }, this));
				return false;
			}

			ali.uploader(upload.next(), 'upload',
			{
				status: l(__m, 'uploading'), params: 'Lang=' + _lang + '&Instance=' + instance + '&Object=' + __object + '&Operation=Upload&FolderName=' + encodeURIComponent(this.Folder.value) + '&TypeID=' + v(panel, 'typeId'), onComplete: function ()
				{
					if (arguments[0] != 0)
					{
						ali.error(arguments[1]);
					}
					else
					{
						upload.val(arguments[1]);

						ali.success(_lang_operation_success);
						ali.working();
					}
				}
			});

			return false;
		};

		this.onAddFolderClick = function ()
		{
			var form = this.form;

			//检查文件夹名称的合法性
			var folderName = form.FolderName.value;
			if (!isFileNameValid(folderName))
			{
				ali.error(l(__m, 'folder_name_invalid'), $.proxy(function () { form.FolderName.select(); }, this));
			}

			//检查文件夹是否已经存在
			var folder = form.Folder;
			folderName = folder.value + "/" + folderName;
			if ($('[value="' + folderName + '"]', folder).length)
			{
				ali.error(l(__m, 'folder_exist'), $.proxy(function () { form.FolderName.select(); }, this));
				return;
			}

			//服务器端添加文件夹
			_helper.post({ instance: instance, object: __object, operation: 'AddFolder&FolderName=' + encodeURIComponent(folderName) + '&TypeID=' + v(panel, 'typeId') });

			//客户端添加文件夹，并且把它选中
			$(form.Folder).append('<option value="' + folderName + '">' + folderName + '</option>');
			form.Folder.selectedIndex = form.Folder.length - 1;
			ali.combo(folder, 'refresh', form.Folder.selectedIndex);
		};

		this.deleteFile = function ()
		{
			var tr = $(this).closest('tr');
			var name = tr.data('id');
			ali.confirm(_lang_confirm_delete, $.proxy(function (returnValue)
			{
				if (returnValue)
				{
					//服务器中删除
					_helper.post({ instance: instance, object: __object, operation: 'DeleteFile', params: 'FileName=' + name + '&FolderName=' + encodeURIComponent($('[name=Folder]', panel).val()) + '&TypeID=' + v(panel, 'typeId') });
					
					//客户端中删除
					ali.grid($('[data-ali-widget=grid]', panel), 'deleteRow', tr[0].rowIndex);
				}

			}, this));

			return false;	
		};

		this.onDeleteFolderClick = function ()
		{
			var folder = $(this.form.Folder);
			if (folder.val() == '/')
			{
				ali.error(l(__m, 'cant_delete_root_folder'));
				return;
			}

			_helper.post({ instance: instance, object: __object, operation: 'DeleteFolder', params: 'FolderName=' + encodeURIComponent(folder.val()) + "&TypeID=" + v(panel, 'typeId')});

			folder.find(':selected').remove();
			ali.combo(folder, 'refresh', folder[0].selectedIndex);
			folder.change();
		};

		function isFileNameValid(name)
		{
			if (name.match(/^(CON\.)|(AUX\.)|(COM1\.)|(COM2\.)|(COM3\.)|(COM4\.)|(LPT1\.)|(LPT2\.)|(LPT3\.)|(PRN\.)|(NUL\.)/))
				return false;

			if (name.match(/^((CON)|(AUX)|(COM1)|(COM2)|(COM3)|(COM4)|(LPT1)|(LPT2)|(LPT3)|(PRN)|(NUL))$/))
				return false;
		
			if (name.length >= 255)
				return false;
	
			if (name.match(/"|'|\/|\\|:|\|/))
				return false;
	
			if (!name.match(/^[a-z]|[A-Z]|\d/))
				return false;
	
			return true;
		}
	}
    //#endregion

    //#region 收入管理
	function Income(instance, panel)
	{
	    var __object = o(arguments.callee);

	    this.settleCpc = function ()
	    {
	        var id = $(this).closest('tr').data('id');
	        ali.confirm(l(__m, 'confirm_settle'), $.proxy(function (returnValue)
	        {
	            if (returnValue)
	            {
	                var startTime = '';
	                if ($('[name=StartTime]', panel).val() != '')
	                    startTime = "&StartTime=" + $('[name=StartTime]', panel).val();

	                var endTime = '';
	                if ($('[name=EndTime]', panel).val() != '')
	                    endTime = "&EndTime=" + $('[name=EndTime]', panel).val();

	                _helper.post({ instance: instance, object: __object, operation: 'SettleCpc', params: 'ID=' + id + startTime + endTime });
	            }

	        }, this));

	        return false;
	    };

	    this.settleCpt = function ()
	    {
	        var id = $(this).closest('tr').data('id');
	        ali.confirm(l(__m, 'confirm_settle'), $.proxy(function (returnValue)
	        {
	            if (returnValue)
	            {
	                _helper.post({ instance: instance, object: __object, operation: 'SettleCpt', params: 'ID=' + id });
	            }

	        },this));

	        return false;
	    };

	    this.deleteIncome = function ()
	    {
	        var id = $(this).closest('tr').data('id');
	        ali.confirm(_lang_confirm_delete, $.proxy(function (returnValue)
	        {
	            if (returnValue)
	            {
	                _helper.post({ instance: instance, object: __object, operation: 'Delete', params: 'ID=' + id, reload: true, element: this });
	            }

	        }, this));

	        return false;
	    };
	}
    //#endregion

    //#region 子实例
	function SubInstance(instance, panel)
	{
		var __object = o(arguments.callee);

		this.add = function ()
		{

			var data = prepareData(this);
			if (!data)
				return false;
			
			_helper.post({ instance: instance, object: __object, operation: 'Add', data: data});

			return false;
		};

		this.modify = function ()
		{
			var data = prepareData(this);
			if (!data)
				return false;

			_helper.post({ instance: instance, object: __object, operation: 'Modify', data: data, params: 'ID=' + v(panel, 'id') });

			return false;
		};

		this.onSelectUserClick = function ()
		{
			ali.dialog({ name: 'SelectUser', modal: true, appendTo: panel, width: 400, height: 200, resizable: false, url: _helper.toAbsPanel(panel, 'user_select.aspx?Lang=' + _lang), onBeforeLoad: _helper.onDialogBeforeLoad, onShow: _helper.onDialogShow });
			return false;
		};

		this.update = function ()
		{
			_helper.update({ instance: instance, object: __object, element: this });
		};

		this.onUserClick = function ()
		{
			$('[name=UserName]', panel).val($(this).text());
			$('[name=UserID]', panel).val($(this).data('id'));

			ali.dialog($(this).closest('.ali-dialog-body').children(), 'close');

			return false;
		};

		function prepareData(form)
		{
			if (form.Name.value == '')
			{
				ali.error(l(__m, 'name_empty'), $.proxy(function () { form.Name.select(); }, this));
				return null;
			}

			if (form.UserName.value == '')
			{
				ali.error(l(__m, 'select_user'), $.proxy(function () { form.UserName.select(); }, this));
				return null;
			}

			var data = _helper.serialize(form);

			return data;
		}

	}
	//#endregion

	//#region  栏目设置
	function InstanceConfig(instance, panel)
	{
		var __object = o(arguments.callee);

		this.rebuild = function ()
		{
			_helper.post({ instance: instance, object: __object, operation: 'Rebuild' });

			return false;
		};

		this.generateCacheFile = function ()
		{
			_helper.post({ instance: instance, object: __object, operation: 'GenerateCacheFile'});

			return false;
		};

	}
	//#endregion
})();
//@ sourceURL=AliCMS.AdModule.js
































